﻿using System;
using DatabaseHelper.Core.Services.Interfaces;
using DatabaseHelper.Core.Services;
using System.Linq;
using System.IO;

namespace DatabaseHelper.CLI
{
    class Program
    {
        static void Main(string[] args)
        {
            //Data Source=DESKTOP-JCARK7Q\SQLEXPRESS2019;Initial Catalog=ContactManager;Persist Security Info=True;User ID=sa;Password=1qaz@WSX3edc

            string server = "172.16.98.213";
            string catalog = "eStoreDB_DEV";
            //string catalog = "NPMS20180912";
            string user = "sa";
            string password = "Sa123456";

            //string server = string.Empty;
            //string catalog = string.Empty;
            //string user = string.Empty;
            //string password = string.Empty;

            try
            {
                //Console.Write("Server\t\t:");
                //server = Console.ReadLine();
                //Console.Write("Catalog\t\t:");
                //catalog = Console.ReadLine();
                //Console.Write("User Id\t\t:");
                //user = Console.ReadLine();
                //Console.Write("Password\t:");
                //password = Console.ReadLine();

                var connectionString = $"Data Source={server};Initial Catalog={catalog};Persist Security Info=True;User ID={user};Password={password};";
                IExcelService excelService = new ExcelService();
                IDatabaseInfoServices databaseInfoServices = new DatabaseInfoServices();
                var data = databaseInfoServices.GetAllColumnsInDatabase(connectionString).Result;
                excelService.ExportDatabaseInfoExcel($"{catalog}_数据库结构导出_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx",
                    Path.Combine(Directory.GetCurrentDirectory(), "Results"), data);
                Console.WriteLine("导出完成");
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
            }
        }
    }
}
